<template>
	<view class="p20">
		<view class=" bg-fff radius20  pl20 pr20 pb42">
			<u-form :model="form" ref="uForm" label-width="auto" :label-style="{color: '#666'}">
				<u-form-item label="就诊人姓名">
					<u-input v-model="form.name" placeholder="请填写就诊人姓名" inputAlign="right" />
				</u-form-item>
				<u-form-item label="就诊人性别">
					<view class="flex w-max row-right">
						<view @click="form.sex=item.sex" v-for="(item,index) in sexList" :key="index" class="flex ml60">
							<image :src="form.sex==item.sex?'/static/img/my/select.png':'/static/img/my/noselect.png'"
								class="h32 w32" mode="" />
							<!-- <switch checked="true" :color="$zs" type="checkbox" /> -->
							<view class="ml24">{{item.name}}</view>
						</view>
					</view>
				</u-form-item>
				<u-form-item label="出生日期">
					<u-input v-model="form.birthday" type="select" @click="show=true" placeholder="请选择出生日期"
						inputAlign="right" />
				</u-form-item>
				<u-picker mode="time" v-model="show" :params="timeParams" :startYear="endYear-120"
					@confirm="e=>form.birthday=e.year+'-'+e.month+'-'+e.day" :endYear="endYear" />
				<!-- <u-form-item label="手机号码" prop="phone">
					<u-input v-model="form.phone" maxlength="11" type="number" placeholder="请填写就诊人手机号"
						inputAlign="right" />
				</u-form-item> -->
				<u-form-item label="身份证号" prop="card_no">
					<u-input v-model="form.card_no" placeholder="请填写就诊人身份证号" inputAlign="right" />
				</u-form-item>
				<auto-select ref="relation" :list="relation_arr" @confirm="form.relation=$event[0].label"></auto-select>
				<u-form-item label="就诊人关系" prop="relation">
					<u-input v-model="form.relation" type="select" @click="$refs.relation.open()" placeholder="请填写就诊人关系"
						inputAlign="right" />
				</u-form-item>

			</u-form>
			<view class="bg-zs color-fff w-max h84 radius12 flex row-center mt60" @click="submit">
				{{form.id?'修改':'+ 添加'}}就诊人
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sexList: [{
						name: '男',
						sex: 1,
					},
					{
						name: '女',
						sex: 2
					}
				],
				form: {
					member_id: '',
					id: '',
					name: "", //	字符串	必填	-	-	就诊人姓名
					sex: 1, //	整型	必填	-	-	性别:0未知
					birthday: "", //	整型	必填	-	-	出生日期
					phone: "", //	字符串	必填	-	-	手机号
					relation: '',
					card_no: "", //	字符串	必填	-	-	身份证号
				},
				show: false,
				timeParams: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				endYear: '',
				relation_arr: []
			};
		},
		onLoad(e) {
			this.relation_arr = this.$config?.relation_arr?.map(label => {
				return {
					label,
				}
			}) || []

			this.endYear = new Date().getFullYear()
			for (let key in this.form) {
				if (e[key]) this.form[key] = e[key]
			}

			if (e.id) {
				uni.setNavigationBarTitle({
					title: '修改就诊人'
				})
				this.getData()
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.$list('rules'))
		},
		methods: {
			getData() {
				this.$request('/master/patient/patientInfo', this.$params).then(res => {
					for (let key in this.form) {
						this.form[key] = res.data[key]
					}
				})
			},
			submit() {
				let api = '/master/patient/patientAdd'
				if (this.form.id) api = '/master/patient/patientEdit'
				this.$refs.uForm.validate(valid => {
					if (!valid) return
					this.$request(api, this.form).then(res => {
						this.$msg(res.msg)
						setTimeout(this.$navBack, 1000)
					})
				})
			}
		}
	}
</script>

<style lang="scss">

</style>